<?php

$form = $this->form('test-form')
	->text('text_single_line','Text (single line)',array(
		'validate' => array(
			array('time', 
				// 'integer_only' => false,
				// 'allow_empty' => false, 
				// 'allow_empty_message' => t('Kakukk'),
				// 'length' => 3,				
				// 'pattern' => '/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i',
			),
		),
		'trim' => false,
	))
	->text('text_single_line_disabled','Text (single line)', array(
		'disabled' => true,
		'value' => 'disabled',
 		'info' => 'Disabled field',
	))
	->text('text_multi_line','Text (multi line)', array(
		'rows' => 4,
	))
	->text('text_multi_line_disabled','Text (multi line, disabled)', array(
		'rows' => 4,
		'disabled' => true,
		'value' => 'disabled',
 		'info' => 'Disabled field',
	))
	->password('password','Password')
	->select('select','Select',array(
		'a' => 'A letter', 
		'b' => 'B letter', 
		'c' => 'C letter', 
	))
	->select('select_disabled','Select (disabled)',array(
		'a' => 'A letter', 
		'b' => 'B letter', 
		'c' => 'C letter', 
	),array(
		'disabled' => true,
 		'info' => 'Disabled field',
	))
	->radio('radio','Radio',array(
		'a' => 'A letter', 
		'b' => 'B letter', 
		'c' => 'C letter', 
	))
	->radio('radio_disabled','Radio (disabled)',array(
		'a' => 'A letter', 
		'b' => 'B letter', 
		'c' => 'C letter', 
	),array(
		'disabled' => true,
 		'info' => 'Disabled field',
	));

$group1 = $form->group('checkbox_group','Checkbox')	
	->checkbox('checkbox','Checkbox')
	->checkbox('checkbox_disabled','Checkbox (disabled)',array(
		'disabled' => true,
 		'info' => 'Disabled field',
	));
	
function cell_renderer($content) {
	return "<b style=\"color: red; \">$content</b>";
}

$form->grid('grid','Grid',array(
		'col1' => 'Column one',
		'col2' => array('label' => 'Column two', 'editable' => true),
		'col3' => array('label' => 'Column three', 'editable' => true),
	),array(
		'a' => array(1,2,3),
		'b' => array(3,2,3),
		'c' => array(1,4,3),
	),array(
		'toolbar' => array(
			'add' => array('label' => 'Add', 'action' => '/grid.add'),
		),
		'buttons' => array(
			'modify' => array('label' => 'Modify', 'action' => '/grid.modify/{#}'),
			'delete' => array('label' => 'Delete', 'action' => '/grid.delete/{#}'),
		),
		'select' => true,
		'table' => false,
	))->grid('grid_disabled','Grid (disabled)',array(
		'col1' => array('label' => 'Column one', 'renderer' => 'cell_renderer'),
		'col2' => 'Column two',
		'col3' => 'Column three',
	),array(
		'a' => array(1,2,3),
		'b' => array(3,2,3),
		'c' => array(1,4,3),
	),array(
		'toolbar' => array(
			'add' => array('label' => 'Add', 'action' => '/grid.add'),
		),
		'buttons' => array(
			'modify' => array('label' => 'Modify', 'action' => '/grid.modify/{#}'),
			'delete' => array('label' => 'Delete', 'action' => '/grid.delete/{#}'),
		),
		'select' => true,
		'disabled' => true,
		'info' => 'Disabled',
	));
	
$form->file('file','File');
$form->image('image','Image');

$form->button('button','Button')
	->button('button_disabled','Button - disabled','submit',array(
		'disabled' => true,
 		'info' => 'Disabled button',
	));

if ($form->submitted()) {
error_log(print_r(($_POST),true));	
	$form->load();
	$form->validate();
	$this->upload()->save($form->value('file'));
	$fields = array('text_single_line','text_multi_line',
		'text_multi_line_disabled','password','select','radio','checkbox');
	// foreach ($fields as $field) {
	// 	$val = $form->value($field);
	// 	$form->messages[$field] = "Value: $val";
	// }
}

$form->render();

?>
